﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using TodoList.Converter;
using TodoList.ViewModel;
using TodoList.Mode;
using TodoList.Common;
using TodoList.View;
using FirstFloor.ModernUI.Windows.Controls;

namespace TodoList.Command
{
   
    class EditCommand : ICommand
    {
        #region ICommand Members
        TodoDeleteBind todoMerget;
        TodoVM vm;
        public bool CanExecute(object parameter)
        {
            todoMerget = parameter as TodoDeleteBind;
            if (todoMerget == null) return true;
            vm = todoMerget.TodoViewModel;
            string id = todoMerget.Id as string;
            if (id == null) return false;
            else return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            //TodoDeleteBind todoMerget = parameter as TodoDeleteBind;
            //TodoVM vm = todoMerget.TodoViewModel;
            string id = todoMerget.Id as string;
            if (id == null) return;
            List<Todo> todoList = Utils.GetTodoList(vm.FileName);
            Todo toEdit = todoList.Where(to => to.Id.Equals(id)).FirstOrDefault();            
            ModernDialog dlog = new ModernDialog();           
            dlog.Title = "Edit Task";
            vm.Todo = toEdit;
            EditControl editCtrl = new EditControl();
            editCtrl.Tag = dlog;
            editCtrl.DataContext = vm;
            dlog.Content = editCtrl;            
            dlog.ShowDialog();            
        }
        #endregion
    }
}
